package written.test;

import javafx.util.Pair;

import java.util.*;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/21  19:11
 * @Description:
 */
public class Huawei21 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int M = sc.nextInt(), N = sc.nextInt();
        HashMap<Integer, Set<Integer>> map = new HashMap<>();
        int[] tmp = new int[M];
        for(int i = 0; i < N; i++){
            int key = sc.nextInt(), val = sc.nextInt();
            tmp[key]++;     tmp[val]++;
            Set<Integer> set = map.get(key);
            if(set == null) set = new HashSet<>();
            set.add(val);
            map.put(key, set);
        }
        created = new HashSet<>();
        creating = new HashSet<>();
        int ans = 10;
        for(int i = 0; i < M; i++) {
            if(tmp[i] == 0) ans--;
            create(i, map);
        }
        ans -= xunhuan ? 2 : 0;
        System.out.println(ans < 0 ? 0:ans);
    }
    static HashSet<Integer> created;
    static HashSet<Integer> creating;
    static boolean xunhuan = false;
    public static void create(int i, Map<Integer, Set<Integer>> map){
        if(created.contains(i) || xunhuan) return;
        Set<Integer> set = map.get(i);
        if(set == null) {
            created.add(i); return;
        }
        creating.add(i);
        for(Integer k : set){
            if(!created.contains(k)){
                if(creating.contains(k)) xunhuan = true;
                else create(k, map);
            }
        }
        creating.remove(i);
    }
}
